package br.com.localfloripa.scheduling;

import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service("scheduledProcessor")
public class ScheduledProcessor implements Processor {
	
	private static final Logger log = LoggerFactory.getLogger(ScheduledProcessor.class);
	
	@Inject
	@Named("garbageCollectorWorker")
	private Worker garbageCollectorWorker;
	
	@Inject
	@Named("reputacaoWorker")
	private Worker reputacaoWorker;
	
	@Inject
	@Named("messageWorker")
	private Worker messageWorker;
	
	@Inject
	@Named("geoCodeWorker")
	private Worker geoCodeWorker;

	@Scheduled(cron="0 0/15 * * * ?")
	@Override
	public void periodicalProcess() {
		try {
			messageWorker.periodicalWork();
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}		
	}

	@Scheduled(cron="0 0 23 * * ?")
	@Override
	public void dailyProcess() {
		try {
			/** limpa diretorio temporario da aplicação **/
			garbageCollectorWorker.dailyWork();			
			
			/** Geocodifica endereços da base de dados **/
			geoCodeWorker.dailyWork();
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}				
	}

	@Scheduled(cron="* * * * 6 ?")
	@Override
	public void weeklyProcess() {
		
	}

}
